package routers

import (
	"github.com/gin-gonic/gin"
	"github.com/liangchao/blogo/src/admin/handler"
	"github.com/liangchao/blogo/src/common/middlewares"
)

func SetupRouter(r *gin.Engine) {

	r.Static("/static", "static")
	r.Static("/css", "static/css")
	r.Static("/js", "static/js")
	r.Static("/assets", "static/assets")
	r.LoadHTMLGlob("views/**/*")
	r.StaticFile("/favicon.ico", "static/images/logo.png")
	r.Use(middlewares.GinLogger(), middlewares.GinRecovery(true))

	{
		// page
		r.GET("/", middlewares.JWTAuth(), handler.GetDashboardPage)
		r.GET("/blogo/dashboard/page", middlewares.JWTAuth(), handler.GetDashboardPage)
		r.GET("/login/page", handler.GetLoginPage)
		r.GET("/blogo/blog/edit/page", middlewares.JWTAuth(), handler.GetEditPage)
		r.GET("/blogo/blog/new/page", middlewares.JWTAuth(), handler.GetEditPage)

		// api
		r.GET("/content-manage", middlewares.JWTAuth(), handler.GetDashboardPage)
		r.GET("/blogo/dashboard/content-manage", middlewares.JWTAuth(), handler.GetDashboardPage)
		r.GET("/blogo/dashboard/info", middlewares.JWTAuth(), handler.GetDashboardInfo)
		r.GET("/blogo/base/captcha", handler.GetCaptcha)
		r.GET("/blogo/blog/query/:page/:limit", handler.QueryBlogListByKeywords)
		r.GET("/blogo/blog/:id", middlewares.JWTAuth(), handler.GetBlogById)

		r.POST("/blog/img", middlewares.JWTAuth(), handler.PostImage)
		r.POST("blogo/blog/new", middlewares.JWTAuth(), handler.NewBlog)

		r.DELETE("blogo/blog/delete", middlewares.JWTAuth(), handler.DeleteBlogById)

		r.POST("/blogo/login/do", handler.DoLogin)
	}
}
